package com.betterman.controller;


import com.betterman.service.PostService;
import com.betterman.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fox
 * @since 2020-08-05
 */
@Api(value="博客", tags={"博客相关接口"})
@RestController
@RequestMapping("/post")
public class PostController extends BaseController {

    /**
     * 博客服务
     */
    @Autowired
    PostService postService;

    @ApiOperation(value="博客列表", notes="获取博客列表", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keywords", value = "查询的名称，中文名/英文名", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "查询的下一个页面的页数，第[page]页", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页的每一页显示的条数", dataType = "integer", paramType = "query")
    })
    @GetMapping("/list")
    public JSONResult queryPosts(String keywords, Integer page, Integer pageSize) {
        if (StringUtils.isBlank(keywords)) {
            keywords = "";
        }
        if (page == null) {
            page = 1;
        }
        if (pageSize == null) {
            pageSize = 9;
        }
        return JSONResult.ok(postService.queryPosts(keywords,page,pageSize));
    }

}
